define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
    if(Config.id == '' || Config.id == null){
        Config.id = 0;
    }
    if(Config.type_id == '' || Config.type_id == null){
        Config.type_id = 0;
    }

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'dnsrecord/index/?id=' + Config.id+'&type_id='+Config.type_id,
                    add_url: 'dnsrecord/add',
                    addbatch_url: 'dnsrecord/addbatch',
                    edit_url: 'dnsrecord/edit',
                    // del_url: 'dnsrecord/del',
                    multi_url: 'dnsrecord/multi',
                    import_url: 'dnsrecord/import',
                    table: 'dns_record',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'new_domain_name', title: __('New_domain_name'), operate: 'LIKE'},
                        {field: 'system_name', title: __('TypeId'), operate: false},
                        // {field: 'name', title: __('Name'), operate: 'LIKE'},
                        // {field: 'type', title: __('Type'), operate: 'LIKE'},
                        // {field: 'info', title: __('Info'), operate: 'LIKE'},
                        // {field: 'ttl', title: __('Ttl')},
                        {field: 'operating_instructions', title: __('Operating_instructions')},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'status', title: __('Status'), searchList: {"normal":__('解析成功'),"hidden":__('解析失败')}, formatter: Table.api.formatter.status,custom: {normal:'success', hidden:'danger'}},
                        {field: 'parsing_information', title: __('ParsingInformation'), operate: 'LIKE'},
                        {field: 'parsing_id', title: __('ParsingId'), operate: 'LIKE'},
                        {field: 'ip', title: __('IP'), operate: 'LIKE'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 添加产品类别
            $(document).on("click", ".btn-addbatch", function () {
                var name = $(this).closest(".operate").data("name");
                Fast.api.open("dnsrecord/addbatch?name=" + name, __('修改DNS'));
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        addbatch: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});